<template>
	<view class="page">
		<view class="duihuanHeader">
			<view class="wenzi">当前红包券</view>
			<view class="flex flex-center">
				<view class="prcie">{{dataInfo.balance4}}</view>
				<view class="wenzis" @click="goUrl('/pages/ConsumeRecord/ConsumeRecord?type=4')">明细</view>
				<tui-icon name="arrowright" color="#fff" :size="20"></tui-icon>
			</view>
			<!-- <view class="flex flex-align flex-center" style="margin-top: 30rpx;">
				<tui-button @click="tui.dianji(duihuan)" width="150rpx" height="150rpx" shape="circle" type="danger" :size="28">兑换</tui-button>
			</view> -->
		</view>
		<view class="goods-data">
			<view class="goods-list">
				<view :class="isList?'list-view':'list-li'" v-for="(item,index) in goodsList" :key="index" v-if="goodsList.length!=0" @click="onGoodsList(item.code)">
					<view class="thumb">
						<image :src="item.cover" mode="heightFix"></image>
					</view>
					<view class="item">
						<view class="title">
							<text class="one-omit">{{item.name}}</text>
						</view>
						<view class="price flex flex-align flex-bt">
							<view class="retail-price">
								<text class="max" v-if="item.price_selling!=0">{{item.price_selling}}+</text>
								<text class="max">{{item.balance3}}红包券</text>
							</view>
							<view class="btns">立即兑换</view>
						</view>
					</view>
				</view>
				<view class="empty-box"  v-if="goodsList.length==0" style="padding-top: 100rpx;">
					<image src="../../static/ic_nodata.png" mode=""></image>
					<view class="">暂无数据</view>
				</view>
			</view>
		</view>
		<tui-modal :show="modal" @cancel="hide" :custom="true" padding="40rpx 30rpx">
			<view class="tui-modal-custom">
				<view class="tui-modal-custom-text" style="margin-bottom: 30rpx;" >
					<view style="font-weight: bold;margin-bottom: 30rpx;font-size: 30rpx;">请选择需要兑换的福利</view>
					<view class="radio flex flex-align" style="margin-bottom: 20rpx;" v-for="(item,index) in fenleiList" :key="index" @click="selcekC(item.id)">
						<radio :checked="isCheck==item.id" value="" color="#f20" style="transform: scale(.7);margin-right: 10rpx;" /><text>{{item.name}}</text>
					</view>
				</view>
				<view class="flex flex-align">
					<tui-button height="72rpx" :size="28" type="white"  @click="hide">取消</tui-button>
					<view class="" style="width: 20rpx;"></view>
					<tui-button height="72rpx" :size="28" type="danger"  @click="handleClick">确定</tui-button>
				</view>
			</view>
		</tui-modal>
		<!-- <DialogBox ref="DialogBox"></DialogBox> -->
	</view>
</template>

<script>
	// 引入mescroll-mixins.js
	export default {
		data() {
			return {
				type:0,
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
				},
				// 列表视图切换
				isList: true,
				// 筛选弹窗
				isScreen: false,
				// 筛选切换
				screenShow: 0,
				// 抽屉
				isDrawer: false,
				keyword: '',
				goodsList:[
				 
				],
				page:1,
				order:'sort',
				sort:'asc',
				entrance_id:'',
				dataInfo:'',
				modal:false,
				isCheck:0,
				fenleiList:[]
			}
		},
		onLoad(params) {
			this.getFenlei()
		},
		onShow() {
			let that = this
			that.getData()
			that.page=1
			that.goodsList = []
			that.getList()
		},
		onReachBottom() {
			let that = this
			that.page++
			that.getList()
		},
		// #ifdef MP
		onShareAppMessage() {
			return {
				title:'分享海报',
				path:'/pages/home/home?inviter_code='+uni.getStorageSync('inviter_code'),
			};
		},
		// #endif
		methods: {
			hide(){
				this.modal = false
			},
			selcekC(e){
				this.isCheck = e
			},
			getFenlei(){
				let that = this
				that.tui.request("api.auth.live/exchangeInfo", "POST", {}, false, false, true).then((res) => {
					if (res.code == 1) {
						that.isCheck =res.data.list[0].id
						that.fenleiList = res.data.list
					}
				}).catch((res) => {})
			},
			duihuan(){
				let that = this
				that.modal = true
				return
				that.$refs['DialogBox'].confirm({
					title: '提示',
					content: '是否要兑换红包福利?',
					DialogType: 'inquiry',
					animation: 0
				}).then(() => {
					that.tui.request("api.auth.live/exchange", "POST", {exchange_red_type:that.isCheck}, false, false, true).then((res) => {
						that.tui.toast(res.info)
						if (res.code == 1) {
							that.page=1
							that.goodsList = []
							that.getList()
							that.getData()
						}
					}).catch((res) => {})
				})
				
			},
			handleClick(){
				let that = this
				that.modal = false
				that.tui.request("api.auth.live/exchange", "POST", {exchange_red_type:that.isCheck}, false, false, true).then((res) => {
					that.tui.toast(res.info)
					if (res.code == 1) {
						if(that.isCheck==2){
							setTimeout(function(){
								that.tui.href('/pages/MyCoupon/MyCoupon')
							},1000)
						}else{
							that.page=1
							that.goodsList = []
							that.getList()
							that.getData()
						}
					}
				}).catch((res) => {})
			},
			goUrl(e){
				this.tui.href(e)
			},
			getData(){
				let that = this
				that.tui.request("api.auth.center/get", "POST", {}, false, false, true).then((res) => {
					if (res.code == 1) {
						that.dataInfo = res.data
					}
				}).catch((res) => {})
			},
			getList(){
				let that = this
				that.tui.request("api.data/goodsRed", "POST", {page:that.page}, false, false, true).then((res) => {
					if (res.code == 1) {
						that.goodsList = that.goodsList.concat(res.data.list)
					}
				}).catch((res) => {})
			},
			/**
			 * 返回点击
			 */
			onBack(){
				uni.navigateBack();
			},
			
			/**
			 * 商品列表点击
			 */
			onGoodsList(e){
				uni.navigateTo({
					url: '/pages/GoodsDetails/GoodsDetails?id='+e,
					animationType: 'zoom-fade-out',
					animationDuration: 200
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import  'SearchGoodsList.scss';
	.duihuanHeader{background:url('/web/static/lipinBj.jpg') no-repeat;padding: 120rpx 0;text-align: center;background-size: 100% 100%;
		.wenzi{color: #fff;font-size: 32rpx;}
		.flex{width: 250rpx;margin: 20rpx auto;font-weight: bold;align-items: center;color: #fff;
			.prcie{font-size:56rpx;margin-top: -10rpx;margin-right: 10rpx;}
			
		}
	}
	.record-list{
		width: 100%;
		background-color: #FFFFFF;
		.list{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 4%;
			height: 140rpx;
			border-bottom: 2rpx solid #f6f6f6;
			.title-date{
				width: 70%;
				height: 100%;
				.title{
					display: flex;
					align-items: center;
					width: 100%;
					height: 60rpx;
					text{
						font-size: 28rpx;
						font-weight: bold;
						color: #222222;
					}
				}
				.date{
					display: flex;
					align-items: center;
					width: 100%;
					height: 60rpx;
					text{
						font-size: 24rpx;
						color: #959595;
					}
				}
			}
			.integral{
				text-align: right;
				view{
					font-size: 28rpx;
					font-weight: bold;
					color: $base;
				}
			}
		}
	}
</style>
